//
//  SEIllManagerCellView.m
//  kuaiyi
//
//  Created by 蒋小哥 on 16/7/7.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "SEIllManagerCellView.h"
#define kFilePath(fileName) ([NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:fileName])

@interface SEIllManagerCellView()

/**
 *  圆圈图片
 */
@property (nonatomic, strong)UIImageView * imgv_box;

/**
 *  竖线
 */
@property (nonatomic, strong)UIView * lineView;

/**
 *  时间label
 */
@property (nonatomic, strong)UILabel * lb_time;

/**
 *  疾病类型
 */
@property (nonatomic, strong)UILabel * lb_caseType;

/**
 *  疾病细分
 */
@property (nonatomic, strong)UILabel * lb_caseSmallType;

/**
 *  疾病描述
 */
@property (nonatomic, strong)UILabel * lb_caseDecription;

/**
 *  照片
 */
@property (nonatomic, strong)UIImageView * imgv_photo;

@end

@implementation SEIllManagerCellView

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
        
    }
    return self;
}

#pragma mark - 创建控件
- (void)setupUI {
    _imgv_box = [[UIImageView alloc]init];
    _imgv_box.image = [UIImage imageNamed:@"illness_rb_img_sel.png"];
    [self.contentView addSubview:self.imgv_box];
    
    _lineView = [[UIView alloc]init];
    _lineView.backgroundColor = kThemeColor;
    [self.contentView addSubview:self.lineView];
    
    _lb_time = [[UILabel alloc]init];
    _lb_time.font = FONT(14);
    [self.contentView addSubview:self.lb_time];
    
    UIImageView * imageView = [[UIImageView alloc]init];
    self.imgv_photo = imageView;
    [self.contentView addSubview:imageView];
    
    _lb_caseType = [[UILabel alloc]init];
    [self.contentView addSubview:self.lb_caseType];
    
    _lb_caseSmallType = [[UILabel alloc]init];
    [self.contentView addSubview:self.lb_caseSmallType];
    
    _lb_caseDecription = [[UILabel alloc]init];
    _lb_caseDecription.numberOfLines = 2;
    _lb_caseDecription.text = @"暂没有具体描述";
    _lb_caseDecription.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.lb_caseDecription];
}

- (void)setModel:(SEIllReportModel *)model {
    _model = model;
    
    _lb_time.text = model.commitTime;
    
    if (model.cassPhotoPath) {
        NSString * imgPath = kFilePath(model.cassPhotoPath);
        UIImage * image = [UIImage imageWithContentsOfFile:imgPath];
        _imgv_photo.image = image;
    }else {
        _imgv_photo.image = nil;
    }
    _lb_caseType.text = [NSString stringWithFormat:@"疾病类型: %@",model.cassBigType];
    _lb_caseSmallType.text = [NSString stringWithFormat:@"基本类型: %@",self.model.cassSmallType];
    
    if (model.cassDescription.length) {
        _lb_caseDecription.text = model.cassDescription;
    }else{
        _lb_caseDecription.text = @"暂没有具体描述";
    }
}

#pragma mark - 设置约束
- (void)setupConstraint{
    [self.imgv_box makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.equalTo(CGSizeMake(20, 20));
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(10);
    }];
    
    [self.lineView makeConstraints:^(MASConstraintMaker *make) {
        make.size.equalTo(CGSizeMake(2, self.contentView.bounds.size.height - 20));
        make.top.equalTo(self.imgv_box.bottom);
        make.left.equalTo((self.imgv_box).centerX);
        make.bottom.equalTo(self.contentView.bottom);
    }];
    
    [self.lb_time makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView.top);
        make.left.equalTo(self.contentView).offset(50);
        make.width.equalTo(300);
    }];
    
    if (self.model.cassPhotoPath) {
        [self.imgv_photo remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.top).offset(34);
            make.left.equalTo(self.contentView).offset(60);
            make.bottom.equalTo(self.contentView.bottom).offset(-25);
            make.width.equalTo(90);
        }];
    }else{
        [self.imgv_photo remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.top).offset(34);
            make.left.equalTo(self.contentView).offset(60);
            make.bottom.equalTo(self.contentView.bottom).offset(-25);
            make.width.equalTo(0);
        }];
    }

    [self.lb_caseType makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lb_time.bottom).offset(10);
        make.left.equalTo(self.imgv_photo.right).offset(10);
    }];
    
    [self.lb_caseSmallType makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lb_caseType.left);
        make.top.equalTo(self.lb_caseType.bottom).offset(10);
    }];
    
    [self.lb_caseDecription makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lb_caseType.left);
        make.top.equalTo(self.lb_caseSmallType.bottom).offset(10);
        make.right.equalTo(self.contentView.right).offset(-15);
    }];
}



#pragma mark
#pragma mark - 布局
- (void)layoutSubviews {
    [super layoutSubviews];

    [self setupConstraint];
    
    
}


@end





